package uiao;

import org.apache.commons.dbcp.BasicDataSource;

import javax.sql.DataSource;

public class DataSourceFactory {

    //定义MySQL的数据库驱动程序
    public static final String DBDRIVER = "com.mysql.cj.jdbc.Driver";
    //定义MySQL数据库的连接地址
    public static final String URL = "jdbc:mysql://localhost:3306/stone?useUnicode=true&useSSL=false&characterEncoding=utf8";
    //MySQL数据库的连接用户名
    public static final String USERNAME = "root";
    //MySQL数据库的连接密码
    public static final String PASSWORD = "1864736adF";

    private static final BasicDataSource dataSource = new BasicDataSource();

    static {
        dataSource.setDriverClassName(DBDRIVER);
        dataSource.setUsername(USERNAME);
        dataSource.setPassword(PASSWORD);
        dataSource.setUrl(URL);
    }

    public static DataSource createDataSource() {
        return dataSource;
    }
}